package com.shenfa.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.shenfa.bean.Epiboly;
import com.shenfa.bean.PaperCityCrd;
/**
 * 
 * 外包商数据库操作类
 * 
 * @author yanglong
 * 
 * @date 2011-8-19
 *
 */
public class EpibolyDao {
	
	@Autowired
	private SqlMapClient sqlMapClient;
	
	/**
	 * 添加外包商
	 * @param t	外包商
	 * @return	0成功，-1失败
	 */
	public int add(Epiboly t) {
		try {
			sqlMapClient.insert("epiboly_manager.add", t);
			return 0;
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
	}

	/**
	 * 删除外包商
	 * @param t	外包商
	 * @return	0成功，-1失败
	 */
	public int del(Epiboly t) {
		try {
			sqlMapClient.delete("epiboly_manager.del", t);
			return 0;
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
	}

	/**
	 * 根据对象条件查询外包商列表
	 * @param t	外包商
	 * @return	外包商列表
	 */
	@SuppressWarnings("unchecked")
	public List<Epiboly> getList(Epiboly t,int start,int limit) {
		List<Epiboly> list = new ArrayList<Epiboly>();
		try {			
			list = sqlMapClient.queryForList("epiboly_manager.getList", t,start,limit);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}
	/**
	 * 查询外包商名称
	 * @param epibolyNo
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<String> getEpibolyName(String epibolyNo) {
		try {
			return sqlMapClient.queryForList("epiboly_manager.queryName", epibolyNo);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}

	public int queryCount(Epiboly t) {
		int a;
		try {
			
			a = (Integer)sqlMapClient.queryForObject("epiboly_manager.queryCount", t);
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
		return a;
	}

	/**
	 * 查询卡产品关联的外包商列表
	 * @param p
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Epiboly> getCondiList(PaperCityCrd p) {
		List<Epiboly> list = new ArrayList<Epiboly>();
		try {
			
			list = sqlMapClient.queryForList("epiboly_manager.getCondiList", p);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}
	
	/**
	 * 更新外包商
	 * @param t	外包商
	 * @return	0成功，-1失败
	 */
	public int upd(Epiboly t) {
		try {
			sqlMapClient.update("epiboly_manager.upd", t);
			return 0;
		} catch (SQLException e) {
			e.printStackTrace();
			return -1;
		}
	}

	/**
	 * 查询所有外包商列表
	 */
	public List<Epiboly> getAllList() {
		List<Epiboly> list = new ArrayList<Epiboly>();
		try {
			list = sqlMapClient.queryForList("epiboly_manager.getAllList");
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		return list;
	}
}
